package top.lixunda.ecommerce.server.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import top.lixunda.commerce.common.core.entity.MessageObject;
import top.lixunda.ecommerce.server.business.BaseController;
import top.lixunda.ecommerce.server.business.api.entity.cache.CacheUser;
import top.lixunda.ecommerce.server.user.api.entity.db.LogLoginDO;
import top.lixunda.ecommerce.server.user.api.controller.ILogLoginController;
import top.lixunda.ecommerce.server.user.service.ILogLoginService;

import java.util.List;

/**
 * @author Xumda
 * @version time:2019/12/16 14:31
 */
@RestController
@Slf4j
public class LogLoginController extends BaseController implements ILogLoginController {

    private final ILogLoginService logLoginService;

    @Autowired
    public LogLoginController(ILogLoginService logLoginService) {
        this.logLoginService = logLoginService;
    }

    @Override
    public MessageObject<List<LogLoginDO>> queryCurrentLogLogin() {
        CacheUser detail = currentUserCacheNotNull();
        List<LogLoginDO> logLoginList = logLoginService.list(
                new LambdaQueryWrapper<LogLoginDO>()
                        .eq(LogLoginDO::getAccountId, detail.getAccount()));
        return getSuccessMessageObject("获取数据数据成功", logLoginList);
    }
}
